@extends('departmentManagement.business.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .business-index-th {
            text-align: center;
            color: #676767;
        }

        .business-index-td {
            text-align: center;
            color: #676767;
        }

        .ico_img {
            width: 90px;
            height: 80px;
            margin-top: -20px;
        }

        .error {
            color: #ff1100;
            display: none;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{asset('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section id="list" class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 0.5vw">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #0080FF">
                                        </i></a>
                                    <a href="{{url('management/business/index')}}"><span
                                                style="font-size: 18px;float: left;margin-top: 5px">&nbsp;首页</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12  col-lg-offset-8 col-md-offset-8">
                                    {{--<form action="{{url('management/business/indexSearch')}}" method="post"--}}
                                          {{--enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                        {{--<input type="search" value="{{$keywords}}" class="search" id="search-input"--}}
                                               {{--name="search">--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-aqua">
                        <div class="inner">
                            <h3>{{$tab['businessNum']}}</h3>
                            <p>业务总数</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/total_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-green">
                        <div class="inner">
                            <h3>{{$tab['businessFile']}}</h3>
                            <p>待上传资料</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/upload_data_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <a href="{{url('management/business/applyNotice')}}">
                        <div class="small-box bg-yellow">
                            <div class="inner">
                                <h3>{{$tab['businessReplyNum']}}</h3>
                                <p>申请通知书</p>
                            </div>
                            <div class="icon">
                                <img class="ico_img" src="{{asset('admin_assets/img/application_notice_icon.png')}}">
                            </div>
                        </div>
                    </a>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-green-gradient">
                        <div class="inner">
                            <h3>{{$tab['businessUnsettled']}}</h3>
                            <p>待结算</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/dealing_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-red">
                        <div class="inner">
                            <h3>{{$tab['businessTailPayment']}}</h3>
                            <p>尾款需结算</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/press_money_icon.png')}}">
                        </div>
                    </div>
                </div>
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-6">
                    <div class="small-box bg-teal-gradient">
                        <div class="inner">
                            <h3>{{$tab['businessFinish']}}</h3>
                            <p>已结单数</p>
                        </div>
                        <div class="icon">
                            <img class="ico_img" src="{{asset('admin_assets/img/finish_icon.png')}}">
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="business-index-th">编号</th>
                                <th class="business-index-th">公司</th>
                                <th class="business-index-th">任务类别</th>
                                <th class="business-index-th">类型</th>
                                <th class="business-index-th">申请人</th>
                                <th class="business-index-th">联系电话</th>
                                <th class="business-index-th">申请日期</th>
                                <th class="business-index-th">款项金额</th>
                                <th class="business-index-th">尾款金额</th>
                                <th class="business-index-th">尾款支付时间</th>
                                <th class="business-index-th">进度</th>
                                <th class="business-index-th">报件资料</th>
                                <th class="business-index-th">操作</th>
                            </tr>
                            </thead>
                            <tbody class="list">
                            @if($product->isEmpty())
                                <tr>
                                    <td class="business-index-td" colspan="12"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @foreach($product as $k =>$v)
                                    @php($item=$v['Product'])
                                    <tr>
                                        <td class="business-index-td">{{$k+1}}</td>
                                        <td class="business-index-td">{{$item['company']}}</td>
                                        <td class="business-index-td is_renew">
                                            @if($v['is_renew']==0)
                                                首次任务
                                            @else
                                                续费任务
                                            @endif
                                        </td>
                                        <td class="business-index-td firstType">{{$v['FirstType']['name']}}</td>
                                        {{--<td class="business-index-td company">{{$item['Product']['company']}}</td>--}}
                                        <td class="business-index-td applicant">{{$item['applicant']}}</td>
                                        <td class="business-index-td phone">{{$item['phone']}}</td>
                                        <td class="business-index-td created_at">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                        <td class="business-index-td price">
                                            @if(empty($v['price']))
                                                暂未设置
                                            @else
                                                ¥{{$v['price']}}
                                            @endif
                                        </td>
                                        <td class="business-index-td tail_payment">
                                            @if(empty($v['tail_payment']))
                                                暂未设置
                                            @else
                                                ¥{{$v['tail_payment']}}
                                            @endif
                                        </td>
                                        <td class="business-index-td tail_pay_time">
                                            @if(empty($v['tail_pay_time']))
                                                暂未支付
                                                @if($v['urge']==1)
                                                    <small class="label pull-right bg-red">催</small>
                                                @endif
                                            @else
                                                {{date("Y-m-d",strtotime($v['tail_pay_time']))}}
                                            @endif
                                        </td>
                                        <td class="business-index-td operation_progress">{{config('config.operation_progress.business')[$v['business_state']]}}</td>
                                        <td class="business-index-td file">
                                            @if(empty($item['file']))
                                                未上传
                                            @else
                                                <a href="{{asset('Uploads/resources/'.$item['file'])}}">资料审阅</a>
                                            @endif
                                        </td>
                                        <td class="business-index-td is_cancel">
                                            @if($v['is_cancel']==$cancel['cancel'])
                                                用户已取消
                                            @else
                                                @if($v['business_state']==$config['waiting_process'])
                                                    <a href="{{url('management/process/productDetail',['id'=>$item['id']])}}"
                                                       target="_blank">查看详情</a>
                                                @elseif($v['business_state']==$config['wait_set_payment'])
                                                    <a href="{{url('management/process/productDetail',['id'=>$item['id']])}}"
                                                       target="_blank">查看详情</a>
                                                    <a href="#" rel="{{$item['id']}}" p="{{$v['id']}}"
                                                       onclick="setId($(this));" data-toggle="modal"
                                                       data-target="#modal-make-money">设置款项</a>
                                                    <span href="#">转接</span>

                                                @elseif($v['business_state']==$config['unliquidated'])
                                                    <a href="{{url('management/process/productDetail',['id'=>$item['id']])}}"
                                                       target="_blank">查看详情</a>
                                                    <a href="#" rel="{{$item['id']}}" p="{{$v['id']}}"
                                                       f="{{$v['first_payment']}}" t="{{$v['price']}}"
                                                       e="{{$v['tail_payment']}}" onclick="setV($(this))"
                                                       data-toggle="modal" data-target="#modal-make-money">修改款项</a>
                                                    <span href="#">转接</span>

                                                @elseif($v['business_state']==$config['first_pay_no_upload'])
                                                    <a href="{{url('management/process/productDetail',['id'=>$item['id']])}}"
                                                       target="_blank">查看详情</a>
                                                    <span href="#">设置款项</span>
                                                    <span href="#">转接</span>
                                                @elseif($v['business_state']==$config['first_pay_upload'])

                                                    <a href="{{url('management/process/productDetail',['id'=>$item['id']])}}"
                                                       target="_blank">查看详情</a>
                                                    <span href="#">设置款项</span>
                                                    <a href="{{url('management/business/transfer',['id'=>$v['id']])}}">转接</a>
                                                @endif
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public/make-moneyModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/list.min.js')}}"></script>
    <script>
        var options = {
            valueNames: ['is_renew', 'firstType','company', 'applicant', 'phone', 'created_at', 'price', 'tail_payment', 'tail_pay_time', 'operation_progress', 'file', 'is_cancel']
        };
        var List = new List('list', options);
        List.search($('#search-input').val());
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });

        function check(e) {
            return !isNaN(e);
        }

        function checkSbt() {
            var t = $('#money-total');
            var f = $('#money-first');
            var e = $('#money-end');
            if (check(t.val()) && check(f.val()) && check(e.val()) && !isContains(t.val()) && !isContains(f.val()) && !isContains(e.val())) {
                return true;
            } else {
                alert('款项填写错误');
                return false;
            }
        }

        $(function () {
            $('#money-first').bind('input propertychange', function () {
                calculate();
                return false;
            });
            $('#money-total').bind('input propertychange', function () {
                calculate();
                minus();
                return false;
            });
            $('#money-end').bind('input propertychange', function () {
                minus();
                return false;
            });
        });

        function minus() {
            var to = $('#money-total');
            var e = $('#money-end');
            var f = $('#money-first');

            if (!check(to.val()) || !check(e.val())) {
                return;
            }
            if (e.val() == '' || isContains(e.val(), '-')) {
                f.val('');
                return;
            }
            if (to == '' || to == 0) {
                f.val('0');
            } else {
                var v = parseFloat(to.val()) - parseFloat(e.val());
                if (isContains(v.toString(), '-')) {
                    v = "款项填写错误";
                }
                f.val(v.toString());
            }
        }

        function isContains(str, substr) {
            return str.indexOf(substr) > -1;
        }

        function calculate() {
            var to = $('#money-total');
            var f = $('#money-first');
            var e = $('#money-end');

            if (!check(to.val()) || !check(f.val())) {
                return;
            }
            if (f.val() == '' || isContains(f.val(), '-')) {
                e.val('');
                return;
            }
            if (to == '' || to == 0) {
                e.val("0");
            } else {
                var v = parseFloat(to.val()) - parseFloat(f.val());
                if (isContains(v.toString(), '-')) {
                    v = "款项填写错误";
                }
                e.val(v.toString());
            }
        }

        function setId(e) {
            $('#product').val(e.attr('rel'));
            $('#progress').val(e.attr('p'));
            $('#money-total').val("");
            $('#money-first').val("");
            $('#money-end').val("");
        }

        function setV(e) {
            $('#product').val(e.attr('rel'));
            $('#progress').val(e.attr('p'));
            $('#money-total').val(e.attr('t'));
            $('#money-first').val(e.attr('f'));
            $('#money-end').val(e.attr('e'));
        }
    </script>
@stop
